package com.lhframework.socket.controller;

import com.alibaba.fastjson.JSON;
import com.lhframework.socket.model.RealTrack;
import com.lhframework.socket.thread.RealTrackThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;

/**
 * Created by lh on 2016/7/6.
 */
@Controller
public class TrackDataController {
    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private SimpMessagingTemplate messagingTemplate;

    @MessageMapping("/data/handle")
    public void dataHandler(String realTrack) {
        logger.info("接收到轨迹数据>>>>>" + JSON.toJSONString(realTrack));
        RealTrack track = JSON.parseObject(realTrack, RealTrack.class);
        RealTrackThread.put(track);
        messagingTemplate.convertAndSend("/topic/track/activity/" + track.getActivityId(), track);
    }

}
